package com.j180.dao.supplier;

import com.j180.bean.Supplier;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 供货商类
 */
public interface ISupplierDao {

    /**
     * 管理员查询所有的供货商
     * @return List类型，供货商集合
     */
    @Select("select su_id as id,\n" +
            "su_supId as supId,\n" +
            "su_name as name,\n" +
            "su_address as address,\n" +
            "su_telNum as telNum,\n" +
            "su_website as website,\n" +
            "su_licensePic as licensePic,\n" +
            "u_id as userId,\n" +
            "u_name as userName,\n" +
            "u_email as email\n" +
            "from t_supplier as sup left join t_user on su_u_id = u_id")
    @ResultMap(value = "result.supplierMap")
    public abstract List<Supplier> getAllSuppliers();

    /**
     * 管理员根据id查询供货商
     * @param id Integer类型，供货商id
     * @return Supplier类，供货商
     */
    @Select("select su_id as id,\n" +
            "su_supId as supId,\n" +
            "su_name as name,\n" +
            "su_address as address,\n" +
            "su_telNum as telNum,\n" +
            "su_website as website,\n" +
            "su_licensePic as licensePic,\n" +
            "u_name as userName,\n" +
            "u_email as email\n" +
            "from t_supplier as sup left join t_user on su_u_id = u_id\n" +
            "where su_id = #{id}")
    @ResultMap(value = "result.supplierMap")
    public abstract Supplier getSuppliersById(@Param("id") Integer id);

    /**
     * 管理员审批通过后添加一个供货商
     * @param supplier Supplier类型，供货商
     * @return int类型，1表示添加成功
     */
    @Insert("insert into t_supplier values(null, #{supId}, #{name}, #{address}, #{telNum}, #{website}, #{licensePic}, #{user.id})")
    public abstract int insertSupplier(Supplier supplier);

    /**
     * 管理员根据id删除一个供货商
     * @param id Integer类型，供货商id
     * @return int类型，1表示删除成功
     */
    @Delete("delete from t_supplier where su_id = #{id}")
    public abstract int deleteSupplier(@Param("id") Integer id);

    /**
     * 管理员修改供货商信息
     * @param supplier Supplier类型，供货商
     * @return int类型，1表示修改成功
     */
    @Update("update t_supplier set su_supId = #{supId}, su_name = #{name}, su_address = #{address}, su_telNum = #{telNum}, su_website = #{website}, su_licensePic = #{licensePic}, su_u_id = #{user.id} where su_id = #{id}")
    public abstract int updateSupplier(Supplier supplier);
}
